<?php

namespace app\shop\controller;
use app\common\controller\Mask;
use think\Config;
use think\Controller;
use think\Db;
use think\Session;


class Base extends Controller {

    /**
     * 默认响应输出类型,支持json/xml
     * @var string
     */
    protected $responseType = 'json';

    protected $timestamp = 0;


    protected $user = null; //用户信息

    protected $station_id = 0;  //子站id

    protected $site = []; //系统配置信息

    protected $domain = ""; //域名

    protected $equipment = "pc"; //客户端设备

    protected $template_path = ""; //模板路径

    protected $avatar = "/uploads/20210106/634991592083b770187ab213c25d022a.jpg"; //默认头像·

    protected $template_name = "default"; //模板名称

    protected $options = [];


    public function _initialize() {

        parent::_initialize(); // TODO: Change the autogenerated stub

        if(isIe()){
            header('location: /ie.html');die;
        }

        $this->timestamp = time();
        $this->site = Config::get("site");
        $this->equipment = is_mobile() ? 'mobile' : 'pc';
        $options = db::name('options')->select();
        foreach($options as $val){
            $this->options[$val['option_name']] = $val['option_content'];
        }
        if(!empty($this->options['active_template'])){
            $active_template = unserialize($this->options['active_template']);
            $this->template_name = $active_template[$this->equipment];
        }
        $template_info_path = ROOT_PATH . 'content/template/' . $this->template_name . '/info.php';
        if(!file_exists($template_info_path)){
            die("<br>您未启用任何模板，请前往后台【网站扩展-模板管理】中开启相应模板。<br><br>如您未安装过网站模板，你需要在后台【网站扩展-插件管理-插件市场】选择安装您的模板");
        }
        $this->template_path = ROOT_PATH . 'content/template/' . $this->template_name . '/';
        includeAction();
        doAction('init');
    }


}
